package com.example.demo.Test;
import com.example.demo.bean.Goods;
import com.example.demo.service.GoodsDao;
import com.example.demo.DemoApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class UserDaoTest_bread {
    @Autowired
    private GoodsDao goodsDao;

    @Test
    public void testInsert(){
        Goods goods = new Goods();
       // user.setId(1L);
        goods.setName("wangwu");
        goods.setAmount(201);
        goods.setPrice(20.1);
        goodsDao.add(goods);
        System.out.println("插入功能完成！");
    }



    @Test
    public void testUpdate(){
        Goods goods = new Goods();
        goods.setId((long) 11);
        goods.setName("zhaoliu");
        goods.setAmount(203);
        goods.setPrice(20.3);
        System.out.println(goodsDao.update(goods));
        System.out.println("更新功能完成！");
    }




    @Test
    public void testDel(){
        goodsDao.del((long) 4);
        System.out.println("删除功能完成！");
    }


    @Test
    public void testFindGoodsById(){
        List<Goods> userList = goodsDao.findGoodsById((long) 11);
        for (Goods usertmp:userList) {
            System.out.println(usertmp.getName()+","+usertmp.getAmount()+","+usertmp.getPrice());
        }
        System.out.println("通过id查找功能完成！");
    }




    @Test
    public void testFindGoodsList(){
        List<Goods> userList = goodsDao.findGoodsList();
        for (Goods usertmp:userList) {
            System.out.println(usertmp.getName()+","+usertmp.getAmount()+","+usertmp.getPrice());
        }
        System.out.println("查找用户列表功能完成！");
    }


}
